﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using ShadowCommando.Game;
using System.Configuration;
using ShadowCommando.Game.Utilites;
using ShadowCommando.Game.Elements.Enemies;
namespace ShadowCommando.Game.Elements
{
    /// <summary>
    /// Klasa reprezentująca przeciwnika
    /// </summary>
   public class Enemy:Character
    {
       /// <summary>
       /// Konstruktor
       /// </summary>
       /// <param name="_step">Krok</param>
       /// <param name="_diff">Poziom trudności</param>
       /// <param name="_enemyId">Id przeciwnika</param>
        public Enemy(int _step,LevelDifficulty _diff,EnemyId _enemyId):base(_step,_diff)
        {
            elementId = ElementId.Enemy;
            enemyId = _enemyId;
            CheckWeapon = new Weapon(step, BulletId.Check, elementId,difficulty);
            Create(enemyId);
            actualWeapon = weapons[0];

            zIndex = 1;
            timerCount = 100000;
        }
        #region Items

        private EnemyId enemyId;
        private Weapon CheckWeapon;
        private int directedHorizontalStep;
        private int directedVerticalStep;
        #endregion
        #region Properties
       /// <summary>
       /// Id przeciwnika
       /// </summary>
        public EnemyId EnemyId
        {
            get { return enemyId; }
            set { enemyId = value; }
        }
        /// <summary>
        /// Krok poziomy
        /// </summary>
        public int DirectedHorizontalStep
        {
            get { return directedHorizontalStep; }
            set { directedHorizontalStep = value; }
        }
       /// <summary>
       /// Krok pionowy
       /// </summary>
        public int DirectedVerticalStep
        {
            get { return directedVerticalStep; }
            set { directedVerticalStep = value; }
        }
        #endregion
        /// <summary>
        /// Strzał przeciwnika
        /// </summary>
        /// <param name="p1"></param>
        /// <returns></returns>
        public Bullet Shoot(Point p1)
        {
            Point p2 = new Point();
            p2.X = FakeX + width / 2;
            p2.Y = FakeY + height / 2;

            if (Math.Sqrt(Math.Pow(p1.X - p2.X, 2) + Math.Pow(p1.Y - p2.Y, 2)) < 1000)
            {
                Bullet b= actualWeapon.Shot(p1, new Point(FakeX, FakeY), cos, sin);
               b.Demage = (int)(demageFactor*b.Demage);
                return b;
            }
            return null;
        }
        /// <summary>
        /// Strzał sprawdzający  czy pocisk dotrze do celu
        /// </summary>
        /// <param name="p1"></param>
        /// <returns></returns>
        public Bullet CheckShoot(Point p1)
        {
            Point p2 = new Point();
            p2.X = FakeX + width / 2;
            p2.Y = FakeY + height / 2;
            if (Math.Sqrt(Math.Pow(p1.X - p2.X, 2) + Math.Pow(p1.Y - p2.Y, 2)) < CheckWeapon.Distance)
                return CheckWeapon.Shot(p1, new Point(FakeX, FakeY), cos, sin);
            return null;
        }
        private void Create(EnemyId id)
        {
            switch ((id))
            {
                case Elements.EnemyId.DroidB1:
                    {
                        LoadSettings(DroidB1Info.Default);
                        weapons.Add(new Weapon(step, BulletId.Laser, elementId, difficulty));
                        break;
                    }
                case EnemyId.DroidB2:
                    {
                        LoadSettings(DroidB2Info.Default);
                        weapons.Add(new Weapon(step, BulletId.Laser, elementId, difficulty));
                        break;
                    }
                case Elements.EnemyId.Droideka:
                    {
                        LoadSettings(Droideka.Default);
                        weapons.Add(new Weapon(step, BulletId.Flechette, elementId, difficulty));
                        break;
                    }
            }
        }
        private void LoadSettings(ApplicationSettingsBase asb)
        {
            Points = (int)asb["Points"];
            Life =(int) asb["Life"];
            Armor = (int)asb["Armor"];

        }
    }
}
